package com.yhy.common.log.config;

import com.yhy.common.log.interceptor.WebInvokeTimeInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 注册自定义拦截器到webmvc
 */
public class WebInvokeTimeConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        WebInvokeTimeInterceptor webInvokeTimeInterceptor = new WebInvokeTimeInterceptor();
        InterceptorRegistration registration = registry.addInterceptor(webInvokeTimeInterceptor);
        registration.excludePathPatterns("/error"); // 排除/error 防止404等情况再匹配到该拦截器
        registration.addPathPatterns("/**");
    }
}

